package com.ynny.service;

import com.ynny.dao.UserDao;
import com.ynny.entity.User;
import com.ynny.entity.UsersDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class UserServicelmpl implements UserService{

    @Autowired
    UserDao userDao;

    @Override
    public int register(UsersDTO user) {
        User repeatUser = userDao.selectUserByUserName(user.getUsername());

        if (repeatUser != null) {
            return 211;
        }

        //新增一个用户
//        List<Integer> hobby = user.getHobby();//list{ 1 , 2,3}
//        //转换成字符串数组 以 ,分割
        String hobbyStr = "";
//        for (Integer h : hobby) {
//            hobbyStr += h + ",";
//        }

        User newUser = new User();
        newUser.setUsername(user.getUsername());
        newUser.setPassword(user.getPassword());
        newUser.setAge(user.getAge());
        newUser.setSex(user.getSex());
//        newUser.setIdentity(user.getIdentity());
        newUser.setHobby(hobbyStr);

        int i = userDao.addUser(newUser);

        if (i != 1) {
            return 212;
        }
        //注册成功送积分

        return 200;



//    @Override
//    public <UserDTO> int register(UsersDTO user) {
//
//
//
//        //TODO: 实现注册逻辑
//        //校验用户是否重复
//

    }
}
